package cn.chengpengper.unit19.client.handler;

import cn.chengpengper.unit19.protocol.response.ListGroupMembersResponsePacket;
import cn.chengpengper.unit19.protocol.session.Session;
import cn.chengpengper.unit19.server.handler.ListGroupMembersRequestHandler;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.util.stream.Collectors;

/**
 * @author huchengpeng
 */
@ChannelHandler.Sharable
public class ListGroupMembersResponseHandler extends SimpleChannelInboundHandler<ListGroupMembersResponsePacket> {

    public static final ListGroupMembersResponseHandler INSTANCE = new ListGroupMembersResponseHandler();

    protected ListGroupMembersResponseHandler(){}

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, ListGroupMembersResponsePacket responsePacket) throws Exception {
        System.out.println("群[" + responsePacket.getGroupId() + "]中的人包括：" + responsePacket.getSessionList().stream().map(Session::getUserName).collect(Collectors.toList()));
    }
}
